package com.zheinfo.web.controller.biz;

import com.zheinfo.biz.domain.Order;
import com.zheinfo.biz.domain.dto.FriendPayOrderDTO;
import com.zheinfo.biz.service.IOrderService;
import com.zheinfo.common.core.controller.BaseController;
import com.zheinfo.common.core.domain.AjaxResult;
import com.zheinfo.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单Controller
 * 
 * @author zheinfo
 */
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController
{
    @Autowired
    private IOrderService orderService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 获取订单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderService.selectOrderById(id));
    }

    /**
     * 新增订单
     */
    @PostMapping
    public AjaxResult add(@RequestBody Order order)
    {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 修改订单
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Order order)
    {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 删除订单
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderService.deleteOrderByIds(ids));
    }

    /**
     * 获取好友代付订单详情
     */
    @GetMapping("/friendPay/{orderNumber}")
    public AjaxResult getFriendPayOrderDetail(@PathVariable String orderNumber)
    {
        FriendPayOrderDTO orderDetail = orderService.getFriendPayOrderDetailByNumber(orderNumber);
        return success(orderDetail);
    }

    /**
     * 拒绝代付
     */
    @PutMapping("/friendPay/refuse/{orderNumber}")
    public AjaxResult refuseFriendPay(@PathVariable String orderNumber)
    {
        return toAjax(orderService.refuseFriendPayByNumber(orderNumber));
    }

    /**
     * 确认代付支付
     */
    @PostMapping("/friendPay/confirm/{orderNumber}")
    public AjaxResult confirmFriendPay(@PathVariable String orderNumber)
    {
        Map<String, String> payParams = orderService.confirmFriendPayByNumber(orderNumber);
        return success(payParams);
    }
}